---
title: "Tess Analyses Replication File"
author: "Sara Morell"
date: "2023-08-13"
output: html_document
---

```{R}
#Load packages
library(sjPlot)
library(ggplot2)
library(stargazer)
library(margins)
library(ggeffects)
library(gridExtra)
library(survey)
library(stats)
library(ggpubr)
library(forcats)
library(dplyr)
library(questionr)


```

```{R}
#PAPER FIGURES AND TABLES
#Read in data -- Survey (Study One)
dynata <- read.csv("surveyfinal.csv")


#FIGURE ONE

#Marginal Effects -- Men
regression1_men <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata[dynata$male == 1,])
summary(regression1_men)

effects_regression1_men = margins(regression1_men)
sum_effects_regression1_men <- summary(effects_regression1_men)

sum_effects_regression1_men <- sum_effects_regression1_men %>%
  mutate(factor = fct_relevel(factor, 
            "family", "pid", "education", 
            "income_01", "homemaker_only", "married", 
            "white", "relig","age","hostile",
            "benevolent","justworld"))

#Graph - results among men
menresults <- ggplot(data = sum_effects_regression1_men) +
  geom_point(aes(factor, AME),color = "black") +
  geom_errorbar(aes(x = factor, ymin = AME - .994*SE, ymax = AME + .994*SE),color = "black") +
  geom_hline(yintercept = 0) +
  theme_minimal() + labs(title = "", x = "Men", y = "Average Marginal Effect on Respondent Pro-Women Attitudes \n (Higher Values = Greater Support)") + scale_x_discrete(labels=c("Family Cues", "Party ID", "Education", "Income", "Homemaker", "Married", "White", "Religious", "Age", "Hostile Sxsm", "Benevolent Sxsm", "Just World")) + scale_y_continuous(limits = c(-.4,.5),breaks = c(-.4,-.3,-.2,-.1,0,.1,.2,.3,.4)) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),axis.title.y = element_text(size = 9))

#Marginal Effects -- women
regression1_women <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata[dynata$female == 1,])
summary(regression1_women)

effects_regression1_women = margins(regression1_women)
sum_effects_regression1_women <- summary(effects_regression1_women)

sum_effects_regression1_women <- sum_effects_regression1_women %>%
  mutate(factor = fct_relevel(factor, 
            "family", "pid", "education", 
            "income_01", "homemaker_only", "married", 
            "white", "relig","age","hostile",
            "benevolent","justworld"))

#Graph -- results among women
womenresults <- ggplot(data = sum_effects_regression1_women) +
  geom_point(aes(factor, AME),color = "black") +
  geom_errorbar(aes(x = factor, ymin = AME - .994*SE, ymax = AME + .994*SE),color = "black") +
  geom_hline(yintercept = 0) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Women", y = "") + scale_x_discrete(labels=c("Family Cues", "Party ID", "Education", "Income", "Homemaker", "Married", "White", "Religious", "Age", "Hostile Sxsm", "Benevolent Sxsm", "Just World")) + scale_y_continuous(limits = c(-.4,.5),breaks = c(-.4,-.3,-.2,-.1,0,.1,.2,.3,.4))

#Figure One -- Paper Text
figureone <- grid.arrange(menresults,womenresults, ncol=2)
ggsave("~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/FigureOne.png", dpi = 700, figureone)





#FIGURE TWO
#Read in data -- Survey Experiment (Study Two)
tess <- read.csv("tessdata_final.csv", header = T, as.is = 1)

regression2_girls <- lm(dv6 ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(regression2_girls)

regression2_boys <- lm(dv6 ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$male == 1,], weights = weight)
summary(regression2_boys)

#Making Predicted Values

predict_fam_girls <- ggpredict(regression2_girls)

predict_fam_girls$ProWomanFam3

predict_fam_boys <- ggpredict(regression2_boys)

predict_fam_boys$ProWomanFam3

girls_family <- ggplot() +
  geom_point(data = 
predict_fam_girls$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(.4,.8) +
  geom_errorbar(data = 
predict_fam_girls$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Teenage Girls", y = "Average Level of Pro-Women Attitudes") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))

boys_family <- ggplot() +
  geom_point(data = 
predict_fam_boys$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(.4,.8) +
  geom_errorbar(data = 
predict_fam_boys$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Teenage Boys", y = "") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))


finalfigure2 <- grid.arrange(girls_family, boys_family, ncol=2)
ggsave("~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/FigureTwo.png", dpi = 700, finalfigure2)

#TABLE ONE
#Results separately for each dependent variable -- Boys Only
bboy <- lm(dv_boys ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 0,], weights = weight)
summary(bboy)

eqboy <- lm(dv_eqpay ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 0,], weights = weight)
summary(eqboy)

hwboy <- lm(dv_hirewmn ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 0,], weights = weight)
summary(hwboy)

tboy <- lm(dv_tampon ~ ProWomanFam3  + inc + relig + city + Biden, data = tess[tess$gender == 0,], weights = weight)
summary(tboy)

sboy <- lm(dv_sexism ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 0,], weights = weight)
summary(sboy)

hboy <- lm(hostilesxsm ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 0,], weights = weight)
summary(hboy)

stargazer(bboy, eqboy, hwboy, tboy, sboy, hboy, type = "html", title = "", covariate.labels = c("Treatment","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Boys","Equal Pay","Hiring Women","Tampons","Sexism","Hostile Sexism"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/TableOne.htm")



```

```{R}

##APPENDIX RESULTS
#STUDY ONE
#Results among full sample (Table 1A)
regression1 <- lm(policy ~ family, data = dynata)
summary(regression1)

regression2 <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age, data = dynata)
summary(regression2)

regression3 <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3)

regression4 <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression4)

stargazer(regression1, regression2, regression3, regression4, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "", out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table1A.htm")



#Interaction between family cues and gender (Table 2A)
regression1_int <- lm(policy ~ family*male, data = dynata)
summary(regression1_int)

regression2_int <- lm(policy ~ family*male + pid + education + income_01 + homemaker_only + married + white + relig + age, data = dynata)
summary(regression2_int)

regression3_int <- lm(policy ~ family*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_int)

regression4_int <- lm(policy ~ family*male + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression4_int)

stargazer(regression1_int, regression2_int, regression3_int, regression4_int, type = "html", title = "", covariate.labels = c("Family Cues","Male","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World","Family Cues x Male"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "", out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table2A.htm")


#Results Among Men Only -- (Table 3A)
regression1M <- lm(policy ~ family, data = dynata[dynata$male == 1,])
summary(regression1M)

regression2M <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age, data = dynata[dynata$male == 1,])
summary(regression2M)

regression3M <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata[dynata$male == 1,])
summary(regression3M)

regression4M <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata[dynata$male == 1,])
summary(regression4M)

stargazer(regression1M, regression2M, regression3M, regression4M, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table3A.htm")



#Results Among Women Only -- (Table 4A)
regression1F <- lm(policy ~ family, data = dynata[dynata$female == 1,])
summary(regression1F)

regression2F <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age, data = dynata[dynata$female == 1,])
summary(regression2F)

regression3F <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata[dynata$female == 1,])
summary(regression3F)

regression4F <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata[dynata$female == 1,])
summary(regression4F)

stargazer(regression1F, regression2F, regression3F, regression4F, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table4A.htm")






#Results On Each Pro-Women Attitude Separately -- (Tables 5A and 6A)
sexism <- lm(sexism ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(sexism)

boys <- lm(boys ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(boys)

abortion <- lm(abortion ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(abortion)

dvclaim <- lm(dvclaim ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(dvclaim)

assault <- lm(assault ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(assault)

eqpay <- lm(eqpay ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(eqpay)

tampons <- lm(tampons ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(tampons)

contraception <- lm(contraception ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(contraception)

hirewmn <- lm(hirewmn ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(hirewmn)


stargazer(sexism, boys, abortion, dvclaim, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Sexism","Boys","Abortion","Domestic Violence"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table5A.htm")


stargazer(assault,eqpay, tampons, contraception, hirewmn, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Campus Assault","Equal Pay","Tampons","Birth Control","Hire Women"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table6A.htm")

#Results Of Each Family Cues Variable Separately -- (Tables 7A)
fc_ym <- lm(policy ~ fc_ym + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(fc_ym)

fc_ep <- lm(policy ~ fc_ep + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(fc_ep)

fc_dt <- lm(policy ~ fc_dt + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(fc_dt)

fc_hrc <- lm(policy ~ fc_hrc + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(fc_hrc)

fc_m2 <- lm(policy ~ fc_m2 + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(fc_m2)

fc_pl <- lm(policy ~ fc_pl + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(fc_pl)

stargazer(fc_ym, fc_ep, fc_dt, fc_hrc, fc_m2, fc_pl, type = "html", title = "", covariate.labels = c("Young Men","Equal Pay","Donald Trump","Hillary Clinton","#MeToo","Pro-Life","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table7A.htm")


#STUDY TWO
#Results of Experiment -- Among Full Sample
#Results Among Family (Table 8A)
reg1 <- lm(dv6 ~ ProWomanFam3, data = tess, weights = weight)
summary(reg1)

reg2 <- lm(dv6 ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg2)

stargazer(reg1, reg2, type = "html", title = "", covariate.labels = c("Treatment (Family Only)","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table8A.htm")

#Results Among Superintendent (Table 9A)
reg3 <- lm(dv6 ~ ProWomanSchool2, data = tess, weights = weight)
summary(reg3)

reg4 <- lm(dv6 ~ ProWomanSchool2 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg4)

stargazer(reg3, reg4, type = "html", title = "", covariate.labels = c("Treatment (Superintendent Only)","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table9A.htm")


#Among Boys Only
#Results Among Family (Table 10A)
reg1b <- lm(dv6 ~ ProWomanFam3, data = tess[tess$male == 1,], weights = weight)
summary(reg1b)

reg2b <- lm(dv6 ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$male == 1,], weights = weight)
summary(reg2b)

stargazer(reg1b, reg2b, type = "html", title = "", covariate.labels = c("Treatment (Family Only)","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table10A.htm")

#Results Among Superintendent (Table 11A)
reg3b <- lm(dv6 ~ ProWomanSchool2, data = tess[tess$male == 1,], weights = weight)
summary(reg3b)

reg4b <- lm(dv6 ~ ProWomanSchool2 + inc + relig + city + Biden, data = tess[tess$male == 1,], weights = weight)
summary(reg4b)

stargazer(reg3b, reg4b, type = "html", title = "", covariate.labels = c("Treatment (Superintendent Only)","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table11A.htm")


#Among Girls Only
#Results Among Family (Table 12A)
reg1g <- lm(dv6 ~ ProWomanFam3, data = tess[tess$gender == 1,], weights = weight)
summary(reg1g)

reg2g <- lm(dv6 ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(reg2g)

stargazer(reg1g, reg2g, type = "html", title = "", covariate.labels = c("Treatment (Family Only)","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table12A.htm")


#Results Among Superintendent (Table 13A)
reg3g <- lm(dv6 ~ ProWomanSchool2, data = tess[tess$gender == 1,], weights = weight)
summary(reg3g)

reg4g <- lm(dv6 ~ ProWomanSchool2 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(reg4g)

stargazer(reg3g, reg4g, type = "html", title = "", covariate.labels = c("Treatment (Superintendent Only)","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table13A.htm")

#Results separately for each dependent variable -- FULL SAMPLE (Table 14A)
reg_b <- lm(dv_boys ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_b)

reg_eq <- lm(dv_eqpay ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_eq)

reg_hw <- lm(dv_hirewmn ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_hw)

reg_t <- lm(dv_tampon ~ ProWomanFam3  + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_t)

reg_s <- lm(dv_sexism ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_s)

reg_h <- lm(hostilesxsm ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_h)

stargazer(reg_b, reg_eq, reg_hw, reg_t, reg_s, reg_h, type = "html", title = "", covariate.labels = c("Treatment","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Boys","Equal Pay","Hiring Women","Tampons","Sexism","Hostile Sexism"), column.sep.width = ".5pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table14A.htm")



#Results separately for each dependent variable -- Girls Only (Table 15A)
bgirl <- lm(dv_boys ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(bgirl)

eqgirl <- lm(dv_eqpay ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(eqgirl)

hwgirl <- lm(dv_hirewmn ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(hwgirl)

tgirl <- lm(dv_tampon ~ ProWomanFam3  + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(tgirl)

sgirl <- lm(dv_sexism ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(sgirl)

hgirl <- lm(hostilesxsm ~ ProWomanFam3 + inc + relig + city + Biden, data = tess[tess$gender == 1,], weights = weight)
summary(hgirl)

stargazer(bgirl, eqgirl, hwgirl, tgirl, sgirl, hgirl, type = "html", title = "", covariate.labels = c("Treatment","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Boys","Equal Pay","Hiring Women","Tampons","Sexism","Hostile Sexism"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table15A.htm")



#Additional Check -- Results on Policy Not Related to Gender (Table 16A)
reg_immigration <- lm(dv_immig ~ ProWomanFam3 + inc + relig + city + Biden, data = tess, weights = weight)
summary(reg_immigration)

stargazer(reg_immigration, type = "html", title = "", covariate.labels = c("Treatment","Family Income","Religious Attendance","City","Parent's Vote"), dep.var.labels = c("Immigration"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table16A.htm")

#Distribution of family members selected by gender (Table 17A)
fammember <- wtd.table(tess$fammember, tess$gender, weights = tess$weight)
prop.table(fammember,2)



#Results Separately for Different Family Members By Gender (Figure 1A)
reg_girlwmn <- lm(dv6 ~ ProWomanFam3, data = tess[tess$fammember == 1 & tess$gender == 1,], weights = weight)
summary(reg_girlwmn)

reg_girlmen <- lm(dv6 ~ ProWomanFam3, data = tess[tess$fammember == 2 & tess$gender == 1,], weights = weight)
summary(reg_girlmen)

reg_boywmn <- lm(dv6 ~ ProWomanFam3, data = tess[tess$fammember == 1 & tess$gender == 0,], weights = weight)
summary(reg_boywmn)

reg_boymen <- lm(dv6 ~ ProWomanFam3, data = tess[tess$fammember == 2 & tess$gender == 0,], weights = weight)
summary(reg_boymen)

### SELECTING MOM AND DAD -- MARGINAL EFFECTS
predict_girlwmn <- ggeffect(reg_girlwmn)

predict_girlmen <- ggeffect(reg_girlmen)

predict_boywmn <- ggeffect(reg_boywmn)

predict_boymen <- ggeffect(reg_boymen)

girlwmn <- ggplot() +
  geom_point(data = 
predict_girlwmn$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(0,1) +
  geom_errorbar(data = 
predict_girlwmn$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Girls Selecting Mom", y = "Avg. Support for Pro-Women Attitudes") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))

girlmen <- ggplot() +
  geom_point(data = 
predict_girlmen$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(0,1) +
  geom_errorbar(data = 
predict_girlmen$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Girls Selecting Dad", y = "Avg. Support for Pro-Women Attitudes") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))

boywmn <- ggplot() +
  geom_point(data = 
predict_boywmn$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(0,1) +
  geom_errorbar(data = 
predict_boywmn$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Boys Selecting Mom", y = "Avg. Support for Pro-Women Attitudes") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))

boymen <- ggplot() +
  geom_point(data = 
predict_boymen$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(0,1) +
  geom_errorbar(data = 
predict_boymen$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Boys Selecting Dad", y = "Avg. Support for Pro-Women Attitudes") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))

figure_fammember <- grid.arrange(girlwmn, girlmen, boywmn, boymen, ncol=2)
ggsave("~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Figure1A.png",figure_fammember,  width = 10, height = 8)


#Robustness Check Based on Superintendent Familiarity (Table 18A)
reg_superfamiliar <- lm(dv6 ~ ProWomanSchool2, data = tess[tess$superind_fam >= .5,], weights = weight)
summary(reg_superfamiliar)

stargazer(reg_superfamiliar, type = "html", title = "", covariate.labels = c("Treatment Group"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table18A.htm")

#Results of Manipulation Check (Table 19A)
manip_fam <- lm(ManipCheck ~ ProWoman, data = tess[tess$FamCue == 1,])
summary(manip_fam)

manip_super <- lm(ManipCheck ~ ProWoman, data = tess[tess$FamCue == 0,])
summary(manip_super)

stargazer(manip_fam,manip_super, type = "html", title = "", covariate.labels = c("Treatment Group"), dep.var.labels = c("Response to Manipulation Check"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Lauren - Mara/PolPsych Submission/Final Figures/Table19A.htm")


```



```{R}

#THINGS WE CUT BUT I WANT TO KEEP IN CASE WE NEED LATER



#Marginal Effects among full sample
effects_regression3 = margins(regression3)
sum_effects_regression3 <- summary(effects_regression3)


combinedsample <- ggplot(data = sum_effects_regression3) +
  geom_point(aes(factor, AME),color = "black") +
  geom_errorbar(aes(x = factor, ymin = lower, ymax = upper),color = "black") +
  geom_hline(yintercept = 0) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Variables", y = "Average Marginal Effect") + scale_x_discrete(labels=c("Age", "Benevolent Sxsm","Education","Family Cues","Homemaker","Hostile Sxsm","Income","Just World","Married","Party ID","Religious","White"))


#Read in Data -- Dynata only among those aware inequality is an issue
dynata_aware <- dynata[dynata$equality > .5 & is.na(dynata$equality) == F,]


#ANALYSES FROM DYNATA SURVEY

#Men Only -- Inequality Awareness (Table 4A)
r1M_aware <- lm(policy ~ family, data = dynata_aware[dynata_aware$male == 1,])
summary(r1M_aware)

r2M_aware <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age, data = dynata_aware[dynata_aware$male == 1,])
summary(r2M_aware)

r3M_aware <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata_aware[dynata_aware$male == 1,])
summary(r3M_aware)

r4M_aware <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata_aware[dynata_aware$male == 1,])
summary(r4M_aware)

stargazer(r1M_aware, r2M_aware, r3M_aware, r4M_aware, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Mara/PolPsych Submission/Final Figures/Table4A.htm")

#Women Only -- Inequality Awareness (Table 5A)
r1F_aware <- lm(policy ~ family, data = dynata_aware[dynata_aware$female == 1,])
summary(r1F_aware)

r2F_aware <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age, data = dynata_aware[dynata_aware$female == 1,])
summary(r2F_aware)

r3F_aware <- lm(policy ~ family + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata_aware[dynata_aware$female == 1,])
summary(r3F_aware)

r4F_aware <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata_aware[dynata_aware$female == 1,])
summary(r4F_aware)

stargazer(r1F_aware, r2F_aware, r3F_aware, r4F_aware, type = "html", title = "", covariate.labels = c("Family Cues","Marriage Cues","Religious Cues","Party ID","Education","Income","Homemaker","Married","White","Religious Obs.","Age","Hostile Sxsm","Benevolent Sxsm", "Just World"), dep.var.labels = c("Support for Pro-Women Attitudes"), column.sep.width = "1pt",font.size = "footnotesize",omit.stat = c("f"), star.cutoffs = c(0.05, 0.01, 0.001), notes.label = "",out = "~/Dropbox/Sara - Mara/PolPsych Submission/Final Figures/Table5A.htm")



#Results separately among white and Black respondents

reg_white <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + relig + age + hostile + benevolent + justworld, data = dynata[dynata$white == 1,])
summary(reg_white)

reg_whiteint <- lm(policy ~ family*male + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + relig + age + hostile + benevolent + justworld, data = dynata[dynata$white == 1,])
summary(reg_whiteint)


reg_black <- lm(policy ~ family + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + relig + age + hostile + benevolent + justworld, data = dynata[dynata$black == 1,])
summary(reg_black)

reg_blackint <- lm(policy ~ family*male + marriage + relig_cost + pid + education + income_01 + homemaker_only + married + relig + age + hostile + benevolent + justworld, data = dynata[dynata$black == 1,])
summary(reg_blackint)



#Results without Trump or Clinton measures in DV
regression4_2 <- lm(policy ~ family2 + marriage2 + relig_cost2 + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression4_2)


regression3_int2 <- lm(policy ~ family2*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_int2)

#Results with Trump and Clinton removed
regression3_noTC <- lm(policy ~ family2 + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_noTC)

regression3_noTCint <- lm(policy ~ family2*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_noTCint)

#Results with each DV separately
regression3_ym <- lm(policy ~ fc_ym + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_ym)

regression3_ymint <- lm(policy ~ fc_ym*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_ymint)

regression3_ep <- lm(policy ~ fc_ep + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_ep)

regression3_epint <- lm(policy ~ fc_ep*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_epint)

regression3_dt <- lm(policy ~ fc_dt + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_dt)

regression3_dtint <- lm(policy ~ fc_dt*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_dtint)

regression3_hrc <- lm(policy ~ fc_hrc + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_hrc)

regression3_hrcint <- lm(policy ~ fc_hrc*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_hrcint)

regression3_m2 <- lm(policy ~ fc_m2 + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_m2)

regression3_m2int <- lm(policy ~ fc_m2*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_m2int)

regression3_pl <- lm(policy ~ fc_pl + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_pl)

regression3_plint <- lm(policy ~ fc_pl*male + pid + education + income_01 + homemaker_only + married + white + relig + age + hostile + benevolent + justworld, data = dynata)
summary(regression3_plint)






predict_super_Women <- ggpredict(reg6g)

predict_super_Women$ProWomanSchool2

predict_super_Men <- ggpredict(reg6b)

predict_super_Men$ProWomanSchool2


men_family2 <- ggplot() +
  geom_point(data = 
predict_fam_Men$ProWomanFam3, aes(x, predicted),color = "black") +
  ylim(.4,.8) +
  geom_errorbar(data = 
predict_fam_Men$ProWomanFam3,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Family Conditions", y = "") + scale_x_continuous(breaks = c(0,.5,1),labels=c("Anti-Women Family","Control","Pro-Women Family"))


men_super <- ggplot() +
  geom_point(data = 
predict_super_Men$ProWomanSchool2, aes(x, predicted),color = "black") +
  ylim(.4,.8) +
  geom_errorbar(data = 
predict_super_Men$ProWomanSchool2,aes(x = x, ymin = predicted -.994*std.error, ymax = predicted +.994*std.error),color = "black") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = "", x = "Superintendent Conditions", y = "Average Level of Support for Pro-Women Attitudes") + scale_x_continuous(breaks = c(0,1),labels=c("Anti-Women Super","Pro-Women Super"))

finalfigure3 <- grid.arrange(men_super, men_family2, ncol = 2)
ggsave("~/Dropbox/Sara - Mara/PolPsych Submission/Final Figures/Figure3.png",finalfigure3)



```

